<?php
namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Query\CategoryQuery;
use App\Http\Query\GoodsQuery;
use App\Http\Query\NewsQuery;

class HomeController extends Controller
{

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('checkAdmin');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        try{
                $goodsQuery = new GoodsQuery();
                $newGoods = $goodsQuery->getNewGoods();

                $newsQuery = new NewsQuery();
                $news = $newsQuery->getNews();

                $CategoryMaster = new CategoryQuery();
                $categoryInfo = $CategoryMaster->getCategoryInfoByLoginId();

                return view('admin.home', array(
                    'newGoods' => $newGoods,
                    'news' => $news,
                    'categoryInfos' => $categoryInfo
                ));
          }catch (\Exception $e){
            \Log::error($e->getFile()." Line:".$e->getLine()." Msg:".$e->getMessage());
        }
    }
}
